<?php

class Bcms_Resource_Adapter_DbTable extends Bcms_Resource_Adapter_Abstract
{
	protected $_dbAdapter;
	
	protected $_tableDef;

	/**
	 * 
	 */
	function __construct($table)
	{
		$db = Zend_Db_Table_Abstract::getDefaultAdapter();
		
		if(!$db){
			throw new Bcms_Resource_Exception('Debe existir una conexion a la base de datos en el registro con la clave Zend_Db');
		}

		$this->_dbAdapter = $db;

		$this->_tableDef = $this->_dbAdapter->describeTable($table);

		$this->_setFields();
		
		$this->setConfig();

		return $this;
	}

	protected function _setFields()
	{
		foreach ($this->_tableDef as $k => $field){
			$f = array();
			if($k != 'id'){
				$f['name']		=	$k;
				$f['default']	=	$field['DEFAULT'];
				$f['length']	=	$field['LENGTH'];
				
				$this->_fields[] = $f;
			}
		}
	}
}